'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const db = uniCloud.database()
	const dbCmd = db.command
	const collection = db.collection('subject-page')
	let size = await collection.count()
	size = size.total
	let index = 0
	let datalist = []
	let notSidallSize = 0 
	let upsize = 0 
	console.log('all size', size)
	while (index < size) {
		const d = await collection
		.field({
			_id: true,
			s_id: true,
			sid:true
		})
		.skip(index)
		.limit(500).get()
		index += d.data.length
		if (d.data.length > 0) {
			for (let s of d.data) {
				
				if(s.sid && s.sid>0){
					console.log('tit')
					continue
				}else{
					notSidallSize++
					s.sid = Number(s.s_id)
					datalist.push(s)
				}
				
			}
		}
	}
	console.log('notSidallSize',notSidallSize,datalist.length)
	
	for(let i=0;i<datalist.length;i++){
		let {sid} = datalist[i]
		await collection.where({
			_id: datalist[i]._id
		}).update({
			sid
		})
		console.log("更新:",datalist.length,i)
	}
	//返回数据给客户端
	return event
};
